<?php

/*
 *  checks the uploaded image and returns a temporary filename if it is valid
 *
 */

function get_img_file(){
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 1024  * 1024 * 3)
&& in_array($extension, $allowedExts)) {
  if ($_FILES["file"]["error"] > 0)
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
  else
    return $_FILES["file"]["tmp_name"];
}
else 
  return false;

}

?>
